package com.freedom.base.service.impl;

import com.freedom.base.mapper.BaseMapper;
import com.freedom.base.query.BaseQuery;
import com.freedom.base.service.IBaseService;
import com.freedom.base.util.PageInfo;
import com.freedom.org.domain.Department;
import com.freedom.org.query.DepartmentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @author freedom
 */
@Service
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> getAll () {
        return baseMapper.getAll();
    }

    @Override
    public T getById ( Serializable id ) {
        return baseMapper.getById(id);
    }

    @Transactional
    @Override
    public void deleteById ( Serializable id ) {
        baseMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void insert ( T t ) {
        baseMapper.insert(t);
    }

    @Transactional
    @Override
    public void update ( T t ) {
        baseMapper.update(t);
    }

    @Override
    public PageInfo<T> queryPage ( BaseQuery query ) {
        Integer total = baseMapper.queryTotal(query);
        if (total != 0) {
            List<T> list = baseMapper.queryPage(query);
            return new PageInfo<T>(total, list);
        }
        return new PageInfo<T>();
    }

    @Override
    public void batchDelete ( List<Long> ids ) {
        baseMapper.batchDelete(ids);
    }

    @Override
    public List<T> getParents () {
        return baseMapper.getParents();
    }


}
